package com.ews.onlineexchange.controller;

import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.primefaces.event.FileUploadEvent;

import com.ews.onlineexchange.model.FeedBack;
import com.ews.onlineexchange.service.EntityHome;
import com.ews.onlineexchange.util.AttachmentUtils;

@Named
@ConversationScoped
public class FeedBackHome extends EntityHome<FeedBack, String> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Inject
	AttachmentUtils attachmentUtils;
	public void uploadImages(FileUploadEvent event) {
		if (event.getFile() == null)
			return ;
		com.ews.onlineexchange.model.Image attr = attachmentUtils.getImageFromUpload(event.getFile());
		getInstance().getImages().add(attr);
		FacesMessage message = new FacesMessage(event.getFile().getFileName() + " 上传成功。");
        FacesContext.getCurrentInstance().addMessage(null, message);
	}
}
